//
//  Cell2ofscroll.m
//  project-A (pianke)
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 scott. All rights reserved.
//

#import "Cell2ofscroll.h"
#import <UIImageView+WebCache.h>
#import "NetworkingHandle.h"
#import "Model3.h"


@interface Cell2ofscroll ()<UIScrollViewDelegate>

@property (nonatomic,retain) UIScrollView *scrollView;
@property (nonatomic,retain) UIImageView *currentImageView;
@property (nonatomic,retain) UIImageView *nextImageView;
@property (nonatomic,retain) UIImageView *preImageView;       //上一个imageView
@property (nonatomic,assign) BOOL isDragging;               //是否正在拖动
@property (nonatomic,retain)NSTimer *timer;

@property (nonatomic,retain)NSMutableArray *arr;

@property (nonatomic,assign)NSInteger number;

@end

@implementation Cell2ofscroll

-(void)dealloc{
    
    [_scrollView release];
    [_currentImageView release];
    [_nextImageView release];
    [_preImageView release];
    [_timer release];
    [_arr release];
    [_mainScollVIew release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        CGFloat height = width * 0.4;

        
        NSMutableArray *viewsArray = [@[] mutableCopy];
        NSArray *colorArray = @[@"11.jpg",@"33.jpg",@"22.jpg",@"11.jpg",@"33.jpg"];
        for (int i = 0; i < 5; ++i) {
            UIImageView *tempLabel = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width,height)];
            [tempLabel setImage:[UIImage imageNamed:[colorArray objectAtIndex:i]]];
            [viewsArray addObject:tempLabel];
        }
        
        self.mainScollVIew = [[CycleScrollView alloc] initWithFrame:CGRectMake(0,0,width,height) animationDuration:2];
        self.mainScollVIew.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
        
        self.mainScollVIew.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
            return viewsArray[pageIndex];
        };
        self.mainScollVIew.totalPagesCount = ^NSInteger(void){
            return 5;
        };
        self.mainScollVIew.TapActionBlock = ^(NSInteger pageIndex){
//            NSLog(@"点击了第%ld个",pageIndex);
        };
        [self addSubview:self.mainScollVIew];
   
        
        
        
        [self geturl];
        

        
          }
    
    return self;
    
}

-(void)geturl{
    NSString *str = @"http://api.lol.zhangyoubao.com/apis/rest/ItemsService/ads?i_=868299012353735&t_=1453979561351&p_=6398&v_=400609&a_=lol&pkg_=com.anzogame.lol&d_=android&osv_=15&cha=tencentMartket&u_=&";
    
    [NetworkingHandle handleWorkData:str AndBody:nil value:nil handleBlock:^(id result) {
        
       
        self.arr = [NSMutableArray array];
       
        
        
        NSMutableArray *arrshuju = [result objectForKey:@"data"];
        for (NSDictionary *dic in arrshuju) {
            
           
            
            [self.arr addObject:[dic objectForKey:@"pic_ad_url"]];
            
          
                    }
    
//        NSLog(@"AAS%@",self.arr);
    
    }];
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
